package net.sxjr.protal.user.service;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import net.sxjr.common.Response;
import net.sxjr.mbg.entity.IgLearningManage;
import net.sxjr.mbg.mapper.IgLearningManageMapper;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * @author ：cuixc
 * @date ：Created in 2020/12/11 15:06
 * @description：
 * @modified By：
 */
@Service
public class LearningManageService {
    @Autowired
    private IgLearningManageMapper learningManageMapper;

    public Response list(String contentType, Integer size, Integer current) {
        LambdaQueryWrapper<IgLearningManage> wrapper = new LambdaQueryWrapper<>();
        if(StringUtils.isNotBlank(contentType)){
            wrapper.eq(IgLearningManage::getLearningType,contentType);
        }
        wrapper.orderByDesc(IgLearningManage::getUploadDate);
        Page<IgLearningManage> page = learningManageMapper.selectPage(new Page<IgLearningManage>(current, size), wrapper);
        return Response.success(page);
    }

    public Response content(String learningId) {
        IgLearningManage manage = learningManageMapper.selectById(learningId);
        manage.updateById();
        return Response.success(manage);
    }
}
